import {defineStore} from "pinia";
import {ref} from "vue";
import {getCurrentUser, loginStatus} from "../api/user.ts";
import {NAMESPACE_USER} from "../interface/user.ts";

//第一个参数是唯一storeId
export const useTokenStore = defineStore("tokenStore",()=>{
    const isAuthenticated = ref<boolean>(false)
    const user = ref<NAMESPACE_USER.UserBase>({})
    const checkAuthenticated = ()=>{
        isAuthenticated.value = loginStatus()
        return isAuthenticated.value
    }
    const currentUser = () =>{
        getCurrentUser().then(data =>{
            if (data.success){
                console.log(data.data)
                user.value = data.data
                console.log(user.value)
            }
        })
    }
    return {
        isAuthenticated,
        user,
        checkAuthenticated,
        currentUser
    }
})
